(function(){

var wrapClass = document.getElementsByTagName('body')[0].children[0].className;
if(wrapClass !== "wrap") {
    return
}
var app = angular.module("myApp",['ngRoute']);

// var urlAddress = "http://localhost/child_watch";
// var urlAddress = "http://115.29.175.93/game/dumen";
var urlAddress = "http://xiongmaozhanjiangshi.oschina.io/hello-world";
// var urlAddress = "http://192.168.10.129/child_watch";

//路由器
app.config(function($routeProvider){
    $routeProvider.
    when("/",{
       controller: 'ind',
       templateUrl: 'view/test.html'
    }).
    when("/index",{
       //首页，默认为手表信息管理页
       controller: 'ind',
       templateUrl: 'view/test.html'
    }).
    when("/watch_msg",{
       // 手表信息管理页面
       controller: 'watch_msg',
       templateUrl: 'view/watch_msg.html',
       resolve : {
          async : getJSON(urlAddress + "/json/watch_msg.json")
       }
    }).
    when("/dev_set",{
       // 设备控制页面
       controller: 'dev_set',
       templateUrl: 'view/dev_set.html',
       resolve : {
          async : function() {
                        return 1
                    }
       }
    }).
    when("/users_sign",{
       // 用户信息管理
       controller: 'users_sign',
       templateUrl: 'view/users_sign.html',
        resolve : {
          async : getJSON(urlAddress + "/json/users_sign.json")
       }
    }).
    when("/us_det",{
       // 用户信息编辑
       controller: 'us_det',
       templateUrl: 'view/user_det.html',
       resolve : {
          async : getJSON(urlAddress + "/json/us_det.json")
        }
    }).
    when("/users_opi",{
       //用户意见反馈
       controller: 'users_opi',
       templateUrl: 'view/users_opi.html',
       resolve : {
          async : getJSON(urlAddress + "/json/users_opi.json")
       }
    }).
    when("/use_aly",{
       //使用频率分析
       controller: 'usAly',
       templateUrl: 'view/use_aly.html'
    }).
    when("/map_aly",{
       //用户地域分析页面
       controller: 'map',
       templateUrl: 'view/map_aly.html',
       resolve: {
          delay : delayJS(urlAddress + "/js/echarts.min.js"),
          async: getJSON(urlAddress + "/json/map.json")
       }
    }).
    when("/hot_aly",{
       // 用户活跃分析页面
       controller: 'hot_aly',
       templateUrl: 'view/hot_aly.html',
       resolve : {
          async : getJSON(urlAddress + "/json/hot_aly.json")
       }
    }).
    when("/watch_state",{
       // 手表状态检测页面
       controller: 'watch_state',
       templateUrl: 'view/watch_state.html',
       resolve : {
          async : getJSON(urlAddress + "/json/watch_state.json")
       }
    }).
    when("/notice",{
       //消息通知页面
       controller: 'notice',
       templateUrl: 'view/notice.html',
        resolve : {
          async : getJSON(urlAddress + "/json/notice.json")
       }
    }).
    when("/account",{
       //账号管理页面
       controller: 'account',
       templateUrl: 'view/account.html',
       resolve : {
          async : getJSON(urlAddress + "/json/account.json")
      }
    }).
    when("/accounter",{
       //账号管理页面
       controller: 'accounter',
       templateUrl: 'view/accounter.html',
       resolve : {
          async : getJSON(urlAddress + "/json/accounter.json")
      }
    }).
    otherwise({
       redirectTo:'/'
    });
});

//设备信息设置
app.controller('dev_set',["$scope","async",function($scope,async){

}])

//管理严个人管理中心
app.controller('accounter',["$scope","async",function($scope,async) {
    //初始化数据
    $scope.init = async.init;
    $scope.initFn = function(data) {
        $scope.name = data.name;
        $scope.parts = data.parts;
        $scope.work = data.work;
        $scope.picSrc = data.picSrc;
    }

    $scope.email = async.init.email;
    $scope.power = async.init.power;
    $scope.initFn($scope.init);

    //控制是否修改信息
    $scope.changeform = true;
    $scope.save = function() {
        $scope.changeform = true;
       $(".sex").addClass("disabled");
    }
    $scope.exit = function() {
          $scope.changeform = true;
         $(".sex").addClass("disabled");
         $scope.initFn(async.init);
    }
    $scope.write = function() {
        $scope.changeform = false;
        $(".sex").removeClass("disabled");
    }

    // 表单验证显示函数 
    $scope.nameblur = function(bool) {
       $scope.nameblur1 = bool;
    }
    $scope.workblur = function(bool) {
       $scope.workblur1 = bool;
    }

    $scope.picFormShow = true;
    $scope.picShow = function(bool) {
        $scope.picFormShow = bool;
    }
    
    $scope.tapconShow = function($event,bool) {
        var tg = $event.target;
        $(tg).removeClass("unshow").siblings().addClass("unshow");
        $scope.tapconshow = bool;
    }

    $scope.checkImg = function($event) {
        var tg = $event.target;
        $("#showPic").attr("src",$(tg).attr("src"));
    }
}]);

//用户地域分析控制器
app.controller('map',["$scope","delay","async",function($scope,delay,async) {
    navTitClass($("nav .map_aly").parent().eq(0));
    
    // 初始化数据
    $scope.opints = async.data;
    $scope.minValue = $scope.opints[1].value;
    $scope.maxValue = $scope.opints[1].value;
    $scope.sum = 0;
    for (var i = 0; i < $scope.opints.length; i++) {
        if ($scope.opints[i].value < $scope.minValue) {
          $scope.minValue = $scope.opints[i].value
        }
    };
    for (var i = 0; i < $scope.opints.length; i++) {
      if ($scope.opints[i].value > $scope.maxValue) {
        $scope.maxValue = $scope.opints[i].value
      }
    };
    for (var i = 0; i < $scope.opints.length; i++) {
        $scope.sum += $scope.opints[i].value
    };
    function setOtherEle() {
        var w = $scope.minValue + $scope.maxValue
        for (var i = 0; i < $scope.opints.length; i++) {
            $scope.opints[i].num = ($scope.opints[i].value*100 / w).toFixed(2);
            $scope.opints[i].pe = ($scope.opints[i].value*100 / $scope.sum).toFixed(2);
        };
    }
    setOtherEle();

    // 滚动设置
    $scope.scroll = function(params) {
        var tgCity = params.name;
        $(".cityName").each(function(){
            var str = $(this).html().split(" ");
            if(tgCity === str[1]) {
                var n = parseInt(str[0]);
                var a = (n - 1) * $(this).parent().outerHeight();
                $(".citys").stop().animate({
                  "scrollTop" : a 
                },500);
                $(this).parent().addClass("checked").siblings().removeClass("checked");
            }
        }) 
    }

    mapinit($scope.opints,$scope.scroll);
}]);

//管理员权限的控制器
app.controller('account',["$scope","async",function($scope,msg) {
     //设备总数
     $scope.number = msg.init.userNumber;
     //当前的页数
     $scope.nowPage = 1;
     // 最大的页数
     $scope.maxPage = 35;

     $scope.hasLastPage = true;
     $scope.pageN = $scope.nowPage;

      // 分页功能
     $scope.pageA = getPageArr($scope.nowPage,$scope.maxPage);
     $scope.afterLi = $scope.pageA.afterLi;
     $scope.beforeLi = $scope.pageA.beforeLi;
     $scope.pageArr = $scope.pageA.arr;
     $scope.hasLastPage = $scope.pageA.hasLastPage;
     $("pages li").each(function() {
          var n = parseInt($(this).html());
     })

     // 设置初始的状态筛选条件和行数显示
     $scope.lineNumbers = [10,15,20];
     $scope.lineNumber = $scope.lineNumbers[0];

     //将获取的数据跟传给控制器
     $scope.opints = msg.data;
     if ($scope.opints.length < 1) {
         $scope.hasSign = true;
     } else {
         $scope.hasSign = false;
     }

     //删除用户
     $scope.delUser = function() {
          // 获取所有被选中的元素及其对应的用户ID
          var delID = [];
          $("table td input").each(function() {
             if ($(this).prop("checked")) {
                delID.push($(this).parents("tr").attr("userID"));
             };
          })
           if(delID.length == 0) {
             alert("你没有选择任何管理员");
           } else {
              console.log(delID);
              // window.location.reload();
           }
      }

      // 全选效果以及反选
      allChecked();

      //设置导航栏中当前页面的背景色
      navTitClass($("nav .account").parent().eq(0));
}])

//手表状态检测的控制器
app.controller('watch_state',["$scope","async",function($scope,msg) {
       //设备总数
       $scope.number = 3227;
       //当前的页数
       $scope.nowPage = 1;
       // 最大的页数
       $scope.maxPage = 10;
       $scope.pageN = $scope.nowPage;

       // 分页功能
       $scope.pageA = getPageArr($scope.nowPage,$scope.maxPage);
       $scope.afterLi = $scope.pageA.afterLi;
       $scope.beforeLi = $scope.pageA.beforeLi;
       $scope.pageArr = $scope.pageA.arr;
       $scope.hasLastPage = $scope.pageA.hasLastPage;

       $("pages li").each(function() {
            var n = parseInt($(this).html());
       })

       // 设置初始的状态筛选条件和行数显示
       $scope.states = [
         {state : "在线", str: "在线"},
         {state : "离线", str: "离线"},
         {state : "全部", str: ""},
       ]
       $scope.stateStr = $scope.states[2];
       $scope.lineNumbers = [10,15,20];
       $scope.lineNumber = $scope.lineNumbers[0];

       //将获取的数据跟传给控制器
       $scope.opints = msg;
       if ($scope.opints.length < 1) {
           $scope.hasSign = true;
       } else {
           $scope.hasSign = false;
       }

        //删除用户
        $scope.delUser = function() {
          // 获取所有被选中的元素及其对应的用户ID
          var delID = [];
          $("table td input").each(function() {
             if ($(this).prop("checked")) {
                delID.push($(this).parents("tr").attr("userID"));
             };
          })
           if(delID.length == 0) {
             alert("你没有选择任何设备");
           } else {
            console.log(delID);
              // window.location.reload();
           }
        }

        // 全选效果以及反选
        allChecked();

        //设置导航栏中当前页面的背景色
       navTitClass($("nav .watch_state").parent().eq(0));
}])

//用户信息管理详情页控制器
app.controller("us_det",["$scope","async",function($scope,msg){
    //初始化数据
    $scope.init = msg.init;
    $scope.initFn = function(data) {
        $scope.name = data.name;
        $scope.account = data.account;
        $scope.sex = data.sex;
        if($scope.sex == "男") {
            $(".sex label").eq(0).addClass("checked").siblings("label").removeClass("checked");
        } else {
            $(".sex label").eq(1).addClass("checked").siblings("label").removeClass("checked");
        }
        $scope.password = data.password;
        $scope.address = data.address;
        $scope.name2 = data.name2;
        $scope.startTime = data.startTime;
        $scope.lastTime = data.lastTime;
    }
    $scope.initFn($scope.init);

    //控制是否修改信息
    $scope.changeform = true;
    $scope.save = function() {
        $scope.changeform = true;
       $(".sex").addClass("disabled");
    }
    $scope.exit = function() {
          $scope.changeform = true;
         $(".sex").addClass("disabled");
         $scope.initFn(msg.init);
    }
    $scope.write = function() {
        $scope.changeform = false;
        $(".sex").removeClass("disabled");
    }
    // 性别造假控制函数
    $scope.checkSex = function($event) {
        var _this = $event.target
        $(_this).parent().addClass("checked").siblings("label").removeClass("checked");
    }

    // 表单验证显示函数 
    $scope.nameblur = function(bool) {
       $scope.nameblur1 = bool;
    }
    $scope.passwordblur = function(bool) {
       $scope.passwordblur1 = bool;
    }
    $scope.addressblur = function(bool) {
       $scope.addressblur1 = bool;
    }
    $scope.name2blur = function(bool) {
       $scope.name2blur1 = bool;
    }

    $scope.opints = msg.data;
}]);

// 用户活跃分析页的控制器
app.controller('hot_aly',["$scope","async",function($scope,msg){
    //初始化数值
    $scope.allDevice = msg.init.allDevice;
    $scope.yestadyAdd = msg.init.yestadyAdd;
    $scope.yestadyOlyDev = msg.init.yestadyOlyDev;
    $scope.yestadyOly = msg.init.yestadyOly;
    $scope.seven = msg.init.seven;
    $scope.thirty = msg.init.thirty;
    $scope.sos = msg.init.sos;

    //引入获取的数据及绘画封装函数并绘制图像
    $scope.select1 = msg.datas;
    $scope.select2 = msg.datas2;
    $scope.drawFn = drawFn();
    $scope.draw1 = function(data) {
        $scope.selectTit1 = data.name;
         var arr = [];
        for (var i = 1; i <= data.data.length; i++) {
            arr[i] =  i;
        };
        $scope.drawFn.drawColumn($('.day_file'),{
           seriseArr : data.data,
           xcate : arr,
           format : data.name.replace("每月","")  + ': <b>{point.y:.0f}</b>'
        });
        $scope.selectShow1 = false;
    }
    $scope.draw2 = function(data) {
        $scope.selectTit2 = data.name;
        $scope.drawFn.drawColumn($('.month_file'),{
           seriseArr : data.data,
           format : data.name.replace("每日","") + ': <b>{point.y:.0f}</b>'
        });
        $scope.selectShow2 = false;
    }
    $scope.draw1($scope.select1[0]);
    $scope.draw2($scope.select2[0]);

    $scope.left = function($event) {
        var _this = $event.target;
        var t = $(_this).next().width();
        $(_this).next().stop().animate({
            "scrollLeft" : $(_this).next().scrollLeft() - t/2
        },800);
    }
    $scope.right = function($event) {
        var _this = $event.target;
        var t = $(_this).prev().width();
        $(_this).siblings(".drawf").stop().animate({
            "scrollLeft" : $(_this).prev().scrollLeft() + t/2
        },800);
    }

    navTitClass($("nav .hot_aly").parent().eq(0));
}])

// 公共组件的控制器
app.controller('myApp', function($scope){
    this.address = urlAddress;

    // nav 导航栏的控制
    $("nav .tit").on("click", function(){
       if(this.onoff) {
          this.onoff = false;
          $(this).parent().removeClass("hide");
       } else {
          this.onoff = true;
          $(this).parent().addClass("hide");
       }
    });
    $(".tap_class").on("click", function() {
       if(this.onoff) {
          this.onoff = false;
          $(this).parents(".nav_box").removeClass("hide_nav");
       } else {
          this.onoff = true;
          $(this).parents(".nav_box").addClass("hide_nav");
       }
       $(".mian").css({
          "paddingLeft": $(".nav_box").width() + "px"
       })
    });
})

//手表信息管理的控制器
app.controller('watch_msg',["$scope","async",function($scope,msg) {
       //设备总数
       $scope.number = 3227;
       //当前的页数
       $scope.nowPage = 1;
       // 最大的页数
       $scope.maxPage = 35;

       $scope.hasLastPage = true;
       $scope.pageN = $scope.nowPage;
       $scope.usUrl = urlAddress + "/#/dev_set"

       // 分页功能
       $scope.pageA = getPageArr($scope.nowPage,$scope.maxPage);
       $scope.afterLi = $scope.pageA.afterLi;
       $scope.beforeLi = $scope.pageA.beforeLi;
       $scope.pageArr = $scope.pageA.arr;
       $scope.hasLastPage = $scope.pageA.hasLastPage;
       $("pages li").each(function() {
            var n = parseInt($(this).html());
       })

       // 设置初始的状态筛选条件和行数显示
       $scope.states = [
         {state : "在线", str: "在线"},
         {state : "离线", str: "离线"},
         {state : "全部", str: ""},
       ]
       $scope.stateStr = $scope.states[2];
       $scope.lineNumbers = [10,15,20];
       $scope.lineNumber = $scope.lineNumbers[0];

       //将获取的数据跟传给控制器
       $scope.opints = msg;
       if ($scope.opints.length < 1) {
           $scope.hasSign = true;
       } else {
           $scope.hasSign = false;
       }

       // 增加用户及相应的表单验证(大部分验证在HTML当中)
       $scope.addForm = true;
       $scope.addUser = function(bool) {
          $scope.addForm = bool;
       }
       $scope.idBool = function(bool) {
          $scope.userform.idBlur = bool;
       }
       $scope.devBool = function(bool) {
          $scope.userform.devBlur = bool;
       }
       $scope.addressBool = function(bool) {
          $scope.userform.addressBlur = bool;
       }
       $scope.accBool = function(bool) {
          $scope.userform.accBlur = bool;
       }

       //删除用户
       $scope.delUser = function() {
          // 获取所有被选中的元素及其对应的用户ID
          var delID = [];
          $("table td input").each(function() {
             if ($(this).prop("checked")) {
                delID.push($(this).parents("tr").attr("userID"));
             };
          })
           if(delID.length == 0) {
             alert("你没有选择任何设备");
           } else {
            console.log(delID);
              // window.location.reload();
           }
       }

        // 全选效果以及反选
        allChecked();

        //设置导航栏中当前页面的背景色
        navTitClass($("nav .watch_msg").parent().eq(0));
}])

//用户信息管理的控制器
app.controller('users_sign',["$scope","async",function($scope,msg) {
       //用户总数
       $scope.number = msg.init.userNumber;
       //当前的页数
       $scope.nowPage = 1;
       // 最大的页数
       $scope.maxPage = 35;

       $scope.hasLastPage = true;
       $scope.pageN = $scope.nowPage;
       $scope.userDet = urlAddress + "/#/us_det"

       // 分页功能
       $scope.pageA = getPageArr($scope.nowPage,$scope.maxPage);
       $scope.afterLi = $scope.pageA.afterLi;
       $scope.beforeLi = $scope.pageA.beforeLi;
       $scope.pageArr = $scope.pageA.arr;
       $scope.hasLastPage = $scope.pageA.hasLastPage;
       $("pages li").each(function() {
            var n = parseInt($(this).html());
       })

       // 设置初始的状态筛选条件和行数显示
       $scope.states = [
         {state : "在线", str: "在线"},
         {state : "离线", str: "离线"},
         {state : "全部", str: ""},
       ];
       //将获取的数据跟传给控制器
       $scope.opints = msg.data;
       if ($scope.opints.length < 1) {
           $scope.hasSign = true;
       } else {
           $scope.hasSign = false;
       }

       $scope.stateStr = $scope.states[2];
       $scope.lineNumbers = [10,15,20];
       $scope.lineNumber = $scope.lineNumbers[0];

       // 增加用户及相应的表单验证(大部分验证在HTML当中)
       $scope.addForm = true;
       $scope.addUser = function(bool) {
          $scope.addForm = bool;
       }
       $scope.idBool = function(bool) {
          $scope.userform.idBlur = bool;
       }
       $scope.devBool = function(bool) {
          $scope.userform.devBlur = bool;
       }
       $scope.addressBool = function(bool) {
          $scope.userform.addressBlur = bool;
       }
       $scope.accBool = function(bool) {
          $scope.userform.accBlur = bool;
       }

       //删除用户
       $scope.delUser = function() {
          // 获取所有被选中的元素及其对应的用户ID
          var delID = [];
          $("table td input").each(function() {
             if ($(this).prop("checked")) {
                delID.push($(this).parents("tr").attr("userID"));
             };
          })
           if(delID.length == 0) {
             alert("你没有选择任何用户");
           } else {
            console.log(delID);
              // window.location.reload();
           }
        }

        // 全选效果以及反选
        allChecked();

        //设置导航栏中当前页面的背景色
        navTitClass($("nav .users_sign").parent().eq(0));
}])

//用户意见反馈控制器
app.controller('users_opi',["$scope","async",function($scope,msg) {
       //用户总数
       $scope.number = msg.init.userNumber;
       //当前的页数
       $scope.nowPage = 1;
       // 最大的页数
       $scope.maxPage = 8;

       $scope.hasLastPage = true;
       $scope.pageN = $scope.nowPage;

       // 分页功能
       $scope.pageA = getPageArr($scope.nowPage,$scope.maxPage);
       $scope.afterLi = $scope.pageA.afterLi;
       $scope.beforeLi = $scope.pageA.beforeLi;
       $scope.pageArr = $scope.pageA.arr;
       $scope.hasLastPage = $scope.pageA.hasLastPage;
       $("pages li").each(function() {
            var n = parseInt($(this).html());
       })

       //将获取的数据跟传给控制器
       $scope.opints = msg.data;
       if ($scope.opints.length < 1) {
           $scope.hasSign = true;
       } else {
           $scope.hasSign = false;
       }

       //控制行数
       $scope.lineNumbers = [10,15,20];
       $scope.lineNumber = $scope.lineNumbers[0];

        //删除信息
        $scope.delUser = function() {
            // 获取所有被选中的元素及其对应的ID
            var delID = [];
            $("table td input").each(function() {
               if ($(this).prop("checked")) {
                  delID.push($(this).parents("tr").attr("userID"));
               };
            })
             if(delID.length == 0) {
               alert("你没有选择任何消息");
             } else {
                 console.log(delID);
                // window.location.reload();
             }
          }

          // 全选效果以及反选
          allChecked();

          //设置导航栏中当前页面的背景色
          navTitClass($("nav .users_opi").parent().eq(0));
}])

//系统消息通知
app.controller('notice',["$scope","async",function($scope,msg) {
      //用户总数
      $scope.number = msg.init.userNumber;
      //当前的页数
      $scope.nowPage = 1;
      // 最大的页数
      $scope.maxPage = 8;

      $scope.hasLastPage = true;
      $scope.pageN = $scope.nowPage;

      // 分页功能
      $scope.pageA = getPageArr($scope.nowPage,$scope.maxPage);
      $scope.afterLi = $scope.pageA.afterLi;
      $scope.beforeLi = $scope.pageA.beforeLi;
      $scope.pageArr = $scope.pageA.arr;
      $scope.hasLastPage = $scope.pageA.hasLastPage;
      $("pages li").each(function() {
        var n = parseInt($(this).html());
      })

      //将获取的数据跟传给控制器
      $scope.opints = msg.data;
      if ($scope.opints.length < 1) {
       $scope.hasSign = true;
      } else {
       $scope.hasSign = false;
      }

      //控制行数
      $scope.lineNumbers = [10,15,20];
      $scope.lineNumber = $scope.lineNumbers[0];

      //删除信息
      $scope.delUser = function() {
      // 获取所有被选中的元素及其对应的用户ID
      var delID = [];
      $("table td input").each(function() {
         if ($(this).prop("checked")) {
            delID.push($(this).parents("tr").attr("userID"));
         };
      })
       if(delID.length == 0) {
         alert("你没有选择任何用户");
       } else {
        console.log(delID);
          // window.location.reload();
       }
      }
      // 增加消息及相应的表单验证(大部分验证在HTML当中)
      $scope.addForm = true;
      $scope.addUser = function(bool) {
      $scope.addForm = bool;
      }
      $scope.checkedUs = function() {
        console.log($scope.checkUs);
      }
      $scope.devBool = function(bool) {
      $scope.userform.devBlur = bool;
      }
      $scope.addressBool = function(bool) {
      $scope.userform.addressBlur = bool;
      }
      $scope.accBool = function(bool) {
      $scope.userform.accBlur = bool;
      }

      // 编辑表单
      $scope.write = function(x) {
      $scope.addForm = true;
      $scope.nt_str = x.notice;
      $scope.nt_title = x.title;
      }
      // 全选效果以及反选
      allChecked();

      //设置导航栏中当前页面的背景色
      navTitClass($("nav .notice").parent().eq(0));
}])

//用户使用频率分析控制器
app.controller('usAly', function($scope){
      $scope.dataShow = true;

      $(".tap_md div").on("click",function(){
        if ($(this).hasClass("un_on")) {
            $(this).removeClass("un_on").siblings().addClass("un_on");
             var str = $(this).html();
             $scope.drawFn.drawColumn($('.form_col'),{
                title : str,
                seriseArr : colArr
             });
        };
      })
      
      //需要的数据原型
      var colData = [
        {
          name: '亮屏',
          y : 800,
          data : [7, 8, 9, 11, 18, 25, 28, 15, 13, 13, 19, 16,7, 8, 9, 11, 18, 25, 28, 15, 13, 13, 19, 16]
        },{
          name: '表情',
          y : 810,
          data : [17, 18, 19, 11, 18, 25, 28, 15, 13, 13, 19, 16,7, 8, 9, 11, 18, 25, 28, 15, 13, 13, 19, 16]
        },{
          name: '拨打电话',
          y : 700,
          data : [27, 18, 19, 21, 28, 15, 18, 27, 23, 13, 19, 26,7, 8, 9, 11, 18, 25, 28, 15, 13, 13, 19, 16]
        },{
          name: '接听电话',
          y : 660,
           data : [23, 12, 11, 26, 28, 12, 18, 27, 23, 17, 12, 24,7, 8, 9, 11, 18, 25, 28, 15, 13, 13, 19, 16]
        },{
          name: '拒听电话',
          y : 350,
          data : [23, 12, 11, 26, 28, 12, 18, 27, 23, 17, 12, 24,7, 8, 9, 11, 18, 25, 28, 15, 13, 13, 19, 16]
        },{
          name: '发送语音',
          y : 450,
          data : [7, 8, 9, 11, 18, 25, 28, 15, 13, 13, 19, 16,7, 8, 9, 11, 18, 25, 28, 15, 13, 13, 19, 16]
        },{
          name: '接收语音',
          y : 550,
          data : [7, 8, 9, 11, 18, 25, 28, 15, 13, 13, 19, 16,7, 8, 9, 11, 18, 25, 28, 15, 13, 13, 19, 16]
        },{
          name: '礼物',
          y : 650,
          data : [27, 18, 19, 21, 28, 15, 18, 27, 23, 13, 19, 26,7, 8, 9, 11, 18, 25, 28, 15, 13, 13, 19, 16]
        },{
          name: '加好友',
          y : 732,
         data : [27, 18, 19, 21, 28, 15, 18, 27, 23, 13, 19, 26,7, 8, 9, 11, 18, 25, 28, 15, 13, 13, 19, 16]
        },{
          name: '二维码',
          y : 654,
         data : [27, 18, 19, 21, 28, 15, 18, 27, 23, 13, 19, 26,7, 8, 9, 11, 18, 25, 28, 15, 13, 13, 19, 16]
        },{
          name: 'SOS',
          y : 333,
          data : [27, 18, 19, 21, 28, 15, 18, 27, 23, 13, 19, 26,7, 8, 9, 11, 18, 25, 28, 15, 13, 13, 19, 16]
        },{
          name: 'home键',
          y : 244,
         data : [23, 12, 11, 26, 28, 12, 18, 27, 23, 17, 12, 24,7, 8, 9, 11, 18, 25, 28, 15, 13, 13, 19, 16]
        },{
          name: '重启',
          y : 544,
          data : [23, 12, 11, 26, 28, 12, 18, 27, 23, 17, 12, 24,7, 8, 9, 11, 18, 25, 28, 15, 13, 13, 19, 16]
        }
      ];

      // 传递给第一个柱状图的数组
      var colArr = [];
      for (var i = 0; i < colData.length; i++) {
         colArr[i] = [colData[i].name,colData[i].y,colData[i].data];
      };

      var lineArr = [];
      for (var i = 0; i < 1; i++) {
        lineArr[i] = {
          name : colData[i].name,
          data : colData[i].data
        }
      };
      var xName = ['1', '2', '3', '4', '5', '6','7', '8', '9', '10', '11', '12','13', '14', '15', '16','17', '18', '19', '20','21', '22', '23', '24'];

      function clickDrawLine(str,arr) {
        var lines = [];
        lines[0] = {
          name : str,
          data : arr
        }
        str = str + "使用统计表";
        $scope.drawFn.drawLine($('.form_line'),{
          title : str,
          seriseArr : lines,
          xcate : xName,
          colorArr : ["#4aa7ea"]
        });
      }

      // 获得绘图所需要的方法
      $scope.drawFn = drawFn();
      $scope.drawFn.drawColumn($('.form_col'),{
        title : "周使用统计表",
        seriseArr : colArr,
      },clickDrawLine);
      $scope.drawFn.drawLine($('.form_line'),{
        title : "亮屏使用统计表",
        seriseArr : lineArr,
        xcate : xName,
        colorArr : ["#4aa7ea"]
      });

      // 日期相关模块
      $scope.getNewData = function(da) {
          console.log(da.year + "年" + da.month + "月");
          $(".now_day").html(da.year + "年" + da.month + "月" + da.date + "日");
          $scope.data = da;
      }

      //创建日期组件
      $scope.dataFn = new dataFn();
      $scope.dataFn.creat($("#data"),$scope.getNewData);

      $scope.prvDay = function() {
        $scope.data.date -= 1;
        if ($scope.data.date <= 0) {
            $scope.data.month -= 1
            if(month <= 0) {
               $scope.data.month = 12;
               $scope.data.year -= 1
            }
            $scope.data.date = $scope.dataFn.getMaxDay($scope.data.month,$scope.data.year);
        }
        $scope.dataFn.init($("#data"),$scope.data);
        $scope.getNewData($scope.data);
      }

      $scope.nowDay = function() {
          if ($scope.dataShow) {
            $scope.dataShow = false;
          } else {
            $scope.dataShow = true;
          }
      }
      $scope.nextDay = function() {
          var maxDays = $scope.dataFn.getMaxDay($scope.data.month,$scope.data.year);
          $scope.data.date += 1;
          if ($scope.data.date > maxDays) {
              $scope.data.date = 1;
              $scope.data.month += 1
              if(month > 12) {
                 $scope.data.month = 1;
                 $scope.data.year += 1
              }
          }
          $scope.dataFn.init($("#data"),$scope.data);
          $scope.getNewData($scope.data);
      }
      navTitClass($("nav .use_aly").parent().eq(0));
})

// 测试页控制器
app.controller('ind', function($scope){
    $scope.sumDevice = 3227;
    $scope.bindDevice = 1277;
    $scope.calls = 277;
    $scope.yesterday = 1030;
 
    // 数据原型
     var barArr = [{
             name: '在线',
             y: 56.33
           }, {
               name: '离线',
               y: 24.03,
               sliced: true,
               selected: true
           }, {
               name: '停机',
               y: 12.2
          }]
     var colArr = [
          ['2016/12', 600],
          ['2016/12', 800],
          ['2016/12', 1000],
          ['2016/9', 1100],
          ['2016/9', 200],
          ['2016/9', 200],
          ['2016/9', 200],
          ['2016/9', 200],
          ['2016/9', 200],
          ['2016/9', 200],
          ['2016/9', 200],
          ['2016/9', 200]
       ]
    // 饼状图点击的回调函数
    function BarClickBack(json,es) {
       console.log(json);
       console.log(es);
    }

    // 获得绘图所需要的方法
   $scope.drawFn = drawFn();
   $scope.drawFn.drawBar($('#device_form'),'设备在线/离线/停机统计',barArr,BarClickBack);
   $scope.drawFn.drawColumn($('#new_Device'),{
        title : "最近一年新增设备",
        seriseArr : colArr
   });
   $scope.drawFn.drawColumn($('#new_User'),{
        title : "最近一年新增设备",
        seriseArr : colArr
   });


   indexOnload();
})

})();